package com.sfj.common.util;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author chengyangliu
 */

@AllArgsConstructor
@NoArgsConstructor
public enum FormDefaultColumnEnum {

    ID("主键","_id", true, true,"int",null),
    CREATETIME("创建时间","create_time",true, true,"timestamp","YYYY-MM-DD HH:mm:ss"),
    CREATEUSER("创建人","create_user", true, true,"string",null),
    UPDATETIME("更新时间","update_time", true, true,"timestamp","YYYY-MM-DD HH:mm:ss"),
    UPDATEUSER("更新人","update_user", true, true,"string",null),
    DELTAG("删除标记","del_tag", false, false,"string",null),
    VERSION("数据版本","version", false, false,"int",null),
    GROUPIDS("群组","group_ids", false, false,"string",null),
    TENANTID("租户id","tenant_id",false,false,"int",null),
    INSTANCEID("流程锁","instance_id",false,true,"string",null),
    ;


    private String show;
    private String code;
    /**
     * 是否能改名称
     */
    private Boolean operate;
    /**
     * 是否查询显示
     */
    private Boolean query;
    /**
     * 是否转时间戳
     */
    private String variable;
    /**
     * 变量格式  yyyy
     */
    private String format;



    public String getFormat() {
        return format;
    }

    public FormDefaultColumnEnum setFormat(String format) {
        this.format = format;
        return this;
    }

    public String getShow() {
        return show;
    }

    public FormDefaultColumnEnum setShow(String show) {
        this.show = show;
        return this;
    }




    public String getCode() {
        return code;
    }

    public FormDefaultColumnEnum setCode(String code) {
        this.code = code;
        return this;
    }

    public Boolean getOperate() {
        return operate;
    }

    public FormDefaultColumnEnum setOperate(Boolean operate) {
        this.operate = operate;
        return this;
    }

    public Boolean getQuery() {
        return query;
    }

    public FormDefaultColumnEnum setQuery(Boolean query) {
        this.query = query;
        return this;
    }


    public String getVariable() {
        return variable;
    }

    public FormDefaultColumnEnum setVariable(String variable) {
        this.variable = variable;
        return this;
    }

    public static boolean containsCode(String key) {
        for (FormDefaultColumnEnum e : FormDefaultColumnEnum.values()) {
            if (e.getCode().equals(key)) {
                return true;
            }
        }
        return false;
    }

    // 返回一个包含所有枚举常量及其属性的列表
    public static List<FormDefaultColumnEnum> getAllColumns() {
        List<FormDefaultColumnEnum> columns = new ArrayList<>();
        for (FormDefaultColumnEnum column : FormDefaultColumnEnum.values()) {
            columns.add(column);
        }
        return columns;
    }

    /**
     * 获取新增时需要屏蔽的字段集合
     */
    public static List<String> getExcludedFieldsForInsert() {
        return Arrays.stream(FormDefaultColumnEnum.values())
                .filter(column -> !FormDefaultColumnEnum.containsCode(column.getCode()))
                .map(FormDefaultColumnEnum::getCode)
                .collect(Collectors.toList());
    }

    //拿中文名称
    public static String getShowByCode(String code) {
        for (FormDefaultColumnEnum field : FormDefaultColumnEnum.values()) {
            if (field.code.equals(code)) {
                return field.show;
            }
        }
        return null;
    }
}